package com.csu.servlet;

import com.alibaba.fastjson.JSON;
import com.csu.entiry.Book;
import com.csu.service.BookService;
import com.csu.service.impl.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(name = "AjaxSearchServlet", urlPatterns = "/AjaxSearchServlet")
public class AjaxSearchServlet extends HttpServlet {
    private final BookService bookService = new BookServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String key = req.getParameter("keyword");
        List<Book> totalList = bookService.getAllBookList(key);

        String result = JSON.toJSONString(totalList);
        resp.setContentType("text/json");
        PrintWriter out = resp.getWriter();
        out.println(result);
    }
}
